﻿#region Apache License
/* 
   Copyright 2011 Jorge Teixeira

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
#endregion

using System;

namespace AdHoc.Wavesque
{
    /// <summary>
    /// Sychronized version of the <see cref="Trianglesque"/> class.
    /// </summary>
    internal class SynchronizedTrianglesque : Trianglesque
    {
        /// <summary>
        /// Synchronization object.
        /// </summary>
        private object syncRoot = new object();

        /// <summary>
        /// Instance of <see cref="Trianglesque"/> class.
        /// </summary>
        private Trianglesque source;

        /// <summary>
        /// Initializes a new instance of the <see cref="SynchronizedTrianglesque"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        public SynchronizedTrianglesque(Trianglesque source)
        {
            this.source = source;
        }

        /// <summary>
        /// Gets a value indicating whether this instance is synchronized.
        /// </summary>
        /// <value>
        /// True if this instance is synchronized.
        /// </value>
        public override bool IsSynchronized { get { return true; } }

        /// <summary>
        /// Calculates a given number of points of a waveform for a given initial position.
        /// </summary>
        /// <param name="numberPoints">Number of points to compute.</param>
        /// <param name="x">Abscissae.</param>
        /// <param name="y">Ordinates.</param>
        /// <param name="x0">Initial position.</param>
        public override void GetValues(uint numberPoints, out double[] x, out double[] y, double x0)
        {
            lock (syncRoot)
            {
                source.GetValues(numberPoints, out x, out y, x0);
            }
        }
    }
}
